﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using KenLib.BusinessObject;
using KenLib.BusinessManager;
using System.Text.RegularExpressions;

public partial class Org_frmO_EmpEnterInput : System.Web.UI.Page
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ViewState["CountingSubmitOrg39"] = Session["CountingSubmitOrg39"];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ((Org_MasterPage)this.Master).changeTitle("入退社情報登録");
        ((Org_MasterPage)this.Master).HideLiArea("frmO_EmpEnterInput");

        //AppCode_Common.ShowEmtyGrid<入退社情報>(grv_human, 5, "データーがありません。", "");

        if (!Page.IsPostBack)
        {
            ViewState["indexPage"] = 0;
            ViewState["IdCurrent"] = "";
            ViewState["state"] = "";
            ViewState["TempTableLoadOrg39ModeIs2"] = null;
            ViewState["TempTableLoadOrg39ModeIs1"] = null;
            ViewState["FirstRowUpdateOrg39"] = true;
            

            // Session nhan thoi gian
            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
            // Load thong tin de hien thi thong diep loi cho cac control loi
            ClearTextPage();
            LoadErrorMessage();

            // Se co 3 truong hop:
            // truong hop 1: mode insert di tu from frmO_EmpBasicInfoInput.aspx den form nay va truyen theo ID
            // truong hop 2: mode update tu frmO_EmpBasicInfo.aspx den trang nay va truyen kem theo ID  ||| with: id=1
            // truong hop 3: mode update tu frm0_EmpBasicInfo.aspx den trang nay va  truyen kem theo Id1 va Id2||| with: id=1 & id2=72
            if (Request.QueryString["id"] != null && Request.QueryString["id2"] == null &&  (Request.QueryString["id3"] == null || Request.QueryString["id3"] != null))
            {
                string _社員ID = Request.QueryString["id"].ToString();
                int _int社員ID;
                Int32.TryParse(_社員ID,out _int社員ID);
                if (_int社員ID == 0)
                    Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + _社員ID);

                btn_次.Enabled = false;
                Session["ModeEmpEnterInputOrg39"] = "1";
                // LoadDataWith_社員ID(_社員ID);
                ShowDataPageLoadFirtInsertMode(_社員ID);
            }
            else if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null && Request.QueryString["id3"] == null)
            {

                string _社員ID = Request.QueryString["id"].ToString();
                string _ID = Request.QueryString["id2"].ToString();
                int _int社員ID;
                int _intID;
                Int32.TryParse(_社員ID, out _int社員ID);
                Int32.TryParse(_社員ID, out _intID);
                if (_int社員ID == 0 && _intID == 0)
                    Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + _社員ID + "&id2=" + _ID);

                Session["ModeEmpEnterInputOrg39"] = "2";
                LoadDataWith_社員ID(_社員ID, _ID);
                LoadDataWith_社員ID_2(_社員ID, _ID);
                btn_次.Enabled = false;
                btn登録.Text = "更新";
            }
            else if (Request.QueryString["id"] == null && Request.QueryString["id2"] == null && Request.QueryString["id3"] == null)
            {
                string _社員ID_ = Session["社員ID"] != null ? Session["社員ID"].ToString() : "";
                if (_社員ID_ != "")
                {
                    Session["ModeEmpEnterInputOrg39"] = "3";
                    ShowDataPageLoadFirtInsertMode(_社員ID_);
                }
            }
            else if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null && Request.QueryString["id3"] != null)
            {
                string _社員ID = Request.QueryString["id"].ToString();
                string _ID = Request.QueryString["id2"].ToString();
                string _id3 = Request.QueryString["id3"].ToString();
                int _int社員ID;
                int _intID;
                Int32.TryParse(_社員ID, out _int社員ID);
                Int32.TryParse(_社員ID, out _intID);
                if (_int社員ID == 0 && _intID == 0)
                    Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + _社員ID + "&id2=" + _ID);
                else
                    if (_int社員ID != 0 && _intID != 0 && _id3 != "1")
                        Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + _社員ID + "&id2=" + _ID + "&id3=" + _id3);

                Session["ModeEmpEnterInputOrg39"] = "4";
                LoadDataWith_社員ID(_社員ID, _ID);
                LoadDataWith_社員ID_2(_社員ID, _ID);
                btn_次.Enabled = false;
                btn登録.Text = "更新";
            }

            ddl_採用区分.Focus();

            Session["url_Org_39"] = "";
            if (Request.UrlReferrer != null)
                Session["url_Org_39"] = Request.UrlReferrer.ToString();
            else
                Session["url_Org_39"] = "~/frmD_Login.aspx";
        }
    }

    /// <summary>
    /// Load thong diep loi vao cac control Validate
    /// </summary>
    private void LoadErrorMessage()
    {
        RegularExpressionValidator1.ErrorMessage = GetError("ER00002");
        //CustomValidator2.ErrorMessage = "入社年月日" + GetError("ER00002");
        RegularExpressionValidator2.ErrorMessage = GetError("ER00002");
        CustomValidator1.ErrorMessage = GetError("ER00005");
        //CustomValidator3.ErrorMessage = "入社年月日" + GetError("ER00001");
        CustomValidator4.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator1.ErrorMessage = GetError("ER00001");
        RequiredFieldValidator3.ErrorMessage = GetError("ER00007");
        //RequiredFieldValidator2.ErrorMessage = GetError("ER00001");
        cusVal.ErrorMessage = GetError("ER00007");
        CustomValidator6.ErrorMessage = GetError("ER00005");
    }

    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        //if (Session["url_Org_39"] == null || Session["url_Org_39"].ToString() == "")
        //{
        //    Response.Redirect("~/frmD_Login.aspx");
        //}
        //else
        //{
        //    Session["backfrmO_EmpBasicInfoInput"] = "true";

        //    string EmpBasicInputIdOfInsert = Session["frm0_EmpBasicInputID"] != null ? Session["frm0_EmpBasicInputID"].ToString() : "";
        //    string stateEmpBasicInfo = Session["frmO_EmpBasicInfo"] != null ? Session["frmO_EmpBasicInfo"].ToString() : "false";

        //    if (EmpBasicInputIdOfInsert != "" && stateEmpBasicInfo == "false")
        //    {
        //        Response.Redirect("frmO_EmpBasicInfoInput.aspx?id=" + EmpBasicInputIdOfInsert);
        //    }
        //    else if (stateEmpBasicInfo == "true")
        //    {
        //        if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null)
        //        {
        //            string id = Request.QueryString["id"].ToString();
        //            string id2 = Request.QueryString["id2"].ToString();
        //            Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + id + "&id2=" + id2);
        //        }
        //        else if (Request.QueryString["id"] != null && Request.QueryString["id2"] == null)
        //        {
        //            string id = Request.QueryString["id"].ToString();
        //            Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + id);
        //        }

        //    }
        //    else
        //        Response.Redirect(Session["url_Org_39"].ToString());
        //}

       
        if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null)
        {
            string id = Request.QueryString["id"].ToString();
            string id2 = Request.QueryString["id2"].ToString();
            Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + id + "&id2=" + id2);
        }
        else if (Request.QueryString["id"] != null && Request.QueryString["id2"] == null)
        {
            string id = Request.QueryString["id"].ToString();
            Response.Redirect("frmO_EmpBasicInfo.aspx?id=" + id);
        }
        else
        {
            string ID = Session["社員ID"] != null ? Session["社員ID"].ToString() : "";
            if (ID != "")
            {
                Response.Redirect("frmO_EmpBasicInfoInput.aspx");
            }
        }
    }

    protected void btn_次_Click(object sender, EventArgs e)
    {
        //Response.Redirect("frmO_EmpContractTypeInput.aspx?id="+Request.QueryString["id"].ToString());
        Response.Redirect("frmO_EmpContractTypeInput.aspx");
    }

    /// <summary>
    /// Load du lieu ung voi 社員ID
    /// </summary>
    /// <param name="_社員ID"></param>
    protected void LoadDataWith_社員ID(string _社員ID)
    {
        入退社情報Manager mana_ = new 入退社情報Manager();
        DataTable dt = mana_.SelectPartialTable(_社員ID);
        if (dt.Rows.Count > 0)
        {
            grv_human.DataSource = dt;
            grv_human.DataBind();
            ViewState["TempTableLoadOrg39ModeIs1"] = dt;
        }
        else
        {
            string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
            ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
        }
    }

    protected void ShowDataPageLoadFirtInsertMode(string _社員ID)
    { 
        入退社情報Manager mana_ = new 入退社情報Manager();
        DataTable dt = mana_.ShowDataPageLoadFirtInsertMode(_社員ID);
        if (dt.Rows.Count > 0)
        {
            grv_human.DataSource = dt;
            grv_human.DataBind();
            ViewState["TempTableLoadOrg39ModeIs1"] = dt;
        }
        else
        {
            string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
            ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
        }
    }

    protected void ShowDataPageLoadAfterInsertMode(string _社員ID)
    {
        入退社情報Manager mana_ = new 入退社情報Manager();
        DataTable dt = mana_.ShowDataPageLoadAfterInsertMode(_社員ID);
        if (dt.Rows.Count > 0)
        {
            grv_human.DataSource = dt;
            grv_human.DataBind();
            ViewState["TempTableLoadOrg39ModeIs1"] = dt;
        }
        else
        {
            string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
            ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
        }
    }

    protected void LoadDataWith_社員ID_2(string _社員ID, string _ID)
    {
        入退社情報Manager mana_ = new 入退社情報Manager();
        DataTable dt = mana_.SelectPartialTable(_社員ID, _ID);
        if (dt.Rows.Count > 0)
        {
            //grv_human.DataSource = dt;
            //grv_human.DataBind();
            //ViewState["TempTableLoadOrg39ModeIs2"] = dt;

            // Hien thi thong tin len cac control
            int index = 0;
            string temp1 = dt.Rows[index]["採用区分"].ToString();
            string temp2 = dt.Rows[index]["入社年月日"].ToString();
            string temp3 = dt.Rows[index]["入社特記事項"].ToString();
            string temp4 = dt.Rows[index]["退社特記事項"].ToString();
            string temp5 = dt.Rows[index]["退職理由"].ToString();
            string temp6 = dt.Rows[index]["退社年月日"].ToString();

            if (temp1 != "")
            {
                ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
            }
            txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
            txt_入社特記事項.Text = temp3;
            txt_退社特記事項.Text = temp4;
            txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

            if (temp5 != "")
            {
                ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
            }
            else
            {
                ddl_退職理由.SelectedIndex = 0;
            }
            ViewState["FirtRowUpdateOrg39"] = true;
        }

    }

    /// <summary>
    /// Load du lieu ung voi 社員ID va ID
    /// </summary>
    /// <param name="_社員ID"></param>
    /// <param name="_ID"></param>
    protected void LoadDataWith_社員ID(string _社員ID, string _ID)
    {
        入退社情報Manager mana_ = new 入退社情報Manager();
        //DataTable dt = mana_.SelectPartialTable(_社員ID, _ID);
        //if (dt.Rows.Count > 0)
        //{
        //    //grv_human.DataSource = dt;
        //    //grv_human.DataBind();
        //    //ViewState["TempTableLoadOrg39ModeIs2"] = dt;
            
        //    // Hien thi thong tin len cac control
        //    int index = 0;
        //    string temp1 = dt.Rows[index]["採用区分"].ToString();
        //    string temp2 = dt.Rows[index]["入社年月日"].ToString();
        //    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
        //    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
        //    string temp5 = dt.Rows[index]["退職理由"].ToString();
        //    string temp6 = dt.Rows[index]["退社年月日"].ToString();

        //    if (temp1 != "")
        //    {
        //        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
        //        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
        //    }
        //    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
        //    txt_入社特記事項.Text = temp3;
        //    txt_退社特記事項.Text = temp4;
        //    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

        //    if (temp5 != "")
        //    {
        //        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
        //        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
        //    }
        //    else
        //    {
        //        ddl_退職理由.SelectedIndex = 0;
        //    }
        //}

        DataTable dt2 = mana_.SelectPartialTable(_社員ID);
        if (dt2.Rows.Count > 0)
        {
            grv_human.DataSource = dt2;
            grv_human.DataBind();
            ViewState["TempTableLoadOrg39ModeIs2"] = dt2;
        }
        else
        {
            string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
            ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
        }

        
    }

    /// <summary>
    /// Lam sach text
    /// </summary>
    protected void ClearTextPage()
    {
        txt_入社年月日.Text = "";
        txt_入社特記事項.Text = "";
        txt_退社年月日.Text = "";
        txt_退社特記事項.Text = "";
        ddl_採用区分.SelectedIndex = 0;
        ddl_退職理由.SelectedIndex = 0;

    }

    protected void grv_human_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_human.PageIndex = e.NewPageIndex;
        ViewState["indexPage"] = e.NewPageIndex.ToString();
        string _myPageMode = Session["ModeEmpEnterInputOrg39"] != null ? Session["ModeEmpEnterInputOrg39"].ToString() : "-1";

         if (_myPageMode == "1")
         {
             string _社員ID = "";
             if (Request.QueryString["id"] != null)
             {
                 _社員ID = Request.QueryString["id"].ToString();
             }
             LoadDataWith_社員ID(_社員ID);
         }

         if (_myPageMode == "3")
         {
             string _社員ID = "";

             _社員ID = Session["社員ID"] != null ? Session["社員ID"].ToString() : "";
             LoadDataWith_社員ID(_社員ID);
         }

         if (_myPageMode == "2" || _myPageMode == "4")
         {
             string _社員ID = "";
             string _Id = "";

             if (Request.QueryString["id"] != null & Request.QueryString["id2"] != null)
             {
                 _社員ID = Request.QueryString["id"].ToString();
                 _Id = Request.QueryString["id2"].ToString();
             }

             LoadDataWith_社員ID(_社員ID, _Id);
         }
    }

    /// <summary>
    /// Lay ra thong diep loi ung voi ma loi
    /// </summary>
    /// <param name="errorid"></param>
    /// <returns></returns>
    public String GetError(string errorid)
    {
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        return dt.Rows[0][2].ToString();
    }

    /// <summary>
    /// Kiem tra dinh dang ngay thang co hop le ko?
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    protected Boolean checkDateValid(String input)
    {
        String pattern = @"^(?ni:(?=\d)((?'year'((1[6-9])|([2-9]\d))\d\d)(?'sep'[/.-])(?'month'0?[1-9]|1[012])\2(?'day'((?<!(\2((0?[2469])|11)\2))31)|(?<!\2(0?2)\2)(29|30)|((?<=((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00)\2\3\2)29)|((0?[1-9])|(1\d)|(2[0-8])))(?:(?=\x20\d)\x20|$))?((?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2}))?)$";
        return Regex.IsMatch(input, pattern);
    }


    /// <summary>
    /// Clear text page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnリセット_Click(object sender, EventArgs e)
    { 
        string _myPageMode = Session["ModeEmpEnterInputOrg39"] != null ? Session["ModeEmpEnterInputOrg39"].ToString() : "-1";

        if (_myPageMode == "1")
        {
                string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
                if (strIdCurrent != "")
                {
                    DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs1"];
                    int index = Int32.Parse(ViewState["indexOrg39"].ToString());

                    string temp1 = dt.Rows[index]["採用区分"].ToString();
                    string temp2 = dt.Rows[index]["入社年月日"].ToString();
                    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                    string temp5 = dt.Rows[index]["退職理由"].ToString();
                    string temp6 = dt.Rows[index]["退社年月日"].ToString();

                    if (temp1 != "")
                    {
                        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                    }
                    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                    txt_入社特記事項.Text = temp3;
                    txt_退社特記事項.Text = temp4;
                    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                    if (temp5 != "")
                    {
                        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                    }
                    else
                    {
                        ddl_退職理由.SelectedIndex = 0;
                    }
                }
                else
                {
                    ClearTextPage();
                    string _社員ID = Request.QueryString["id"].ToString();
                    ShowDataPageLoadFirtInsertMode(_社員ID);
                }
        }

        if (_myPageMode == "2")
        {
            string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
            if (strIdCurrent != "")
            {
                DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs2"];
                if (dt != null && dt.Rows.Count > 0)
                {
                    int index = Int32.Parse(ViewState["indexOrg39"].ToString());
                    string temp1 = dt.Rows[index]["採用区分"].ToString();
                    string temp2 = dt.Rows[index]["入社年月日"].ToString();
                    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                    string temp5 = dt.Rows[index]["退職理由"].ToString();
                    string temp6 = dt.Rows[index]["退社年月日"].ToString();

                    if (temp1 != "")
                    {
                        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                    }
                    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                    txt_入社特記事項.Text = temp3;
                    txt_退社特記事項.Text = temp4;
                    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                    if (temp5 != "")
                    {
                        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                    }
                    else
                    {
                        ddl_退職理由.SelectedIndex = 0;
                    }
                }
            }
            else
            {
                
                bool check = ViewState["FirstRowUpdateOrg39"] != null ? (bool)ViewState["FirstRowUpdateOrg39"] : false;
                if (check)
                {
                    string _社員ID = Request.QueryString["id"].ToString();
                    string _ID = Request.QueryString["id2"].ToString();

                    LoadDataWith_社員ID_2(_社員ID, _ID);
                }
                else
                {
                    ClearTextPage();
                    string _社員ID = Request.QueryString["id"].ToString();
                    string _ID = Request.QueryString["id2"].ToString();
                    LoadDataWith_社員ID(_社員ID, _ID);
                }
            }
        }


        if (_myPageMode == "3")
        {
            string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
            if (strIdCurrent != "")
            {
                DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs1"];
                int index = Int32.Parse(ViewState["indexOrg39"].ToString());

                string temp1 = dt.Rows[index]["採用区分"].ToString();
                string temp2 = dt.Rows[index]["入社年月日"].ToString();
                string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                string temp5 = dt.Rows[index]["退職理由"].ToString();
                string temp6 = dt.Rows[index]["退社年月日"].ToString();

                if (temp1 != "")
                {
                    ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                    ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                }
                txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                txt_入社特記事項.Text = temp3;
                txt_退社特記事項.Text = temp4;
                txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                if (temp5 != "")
                {
                    ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                    ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                }
                else
                {
                    ddl_退職理由.SelectedIndex = 0;
                }
            }
            else
            {
                ClearTextPage();
                string _社員ID = Session["社員ID"].ToString();
                ShowDataPageLoadFirtInsertMode(_社員ID);
            }
        }

        if (_myPageMode == "4")
        {
            string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
            if (strIdCurrent != "")
            {
                DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs2"];
                if (dt != null && dt.Rows.Count > 0)
                {
                    int index = Int32.Parse(ViewState["indexOrg39"].ToString());
                    string temp1 = dt.Rows[index]["採用区分"].ToString();
                    string temp2 = dt.Rows[index]["入社年月日"].ToString();
                    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                    string temp5 = dt.Rows[index]["退職理由"].ToString();
                    string temp6 = dt.Rows[index]["退社年月日"].ToString();

                    if (temp1 != "")
                    {
                        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                    }
                    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                    txt_入社特記事項.Text = temp3;
                    txt_退社特記事項.Text = temp4;
                    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                    if (temp5 != "")
                    {
                        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                    }
                    else
                    {
                        ddl_退職理由.SelectedIndex = 0;
                    }
                }
            }
            else
            {

                bool check = ViewState["FirstRowUpdateOrg39"] != null ? (bool)ViewState["FirstRowUpdateOrg39"] : false;
                if (check)
                {
                    string _社員ID = Request.QueryString["id"].ToString();
                    string _ID = Request.QueryString["id2"].ToString();

                    LoadDataWith_社員ID_2(_社員ID, _ID);
                }
                else
                {
                    ClearTextPage();
                    string _社員ID = Request.QueryString["id"].ToString();
                    string _ID = Request.QueryString["id2"].ToString();
                    LoadDataWith_社員ID(_社員ID, _ID);
                }
            }
        }


        ddl_採用区分.Focus();
    }
   

    /// <summary>
    /// chuyen chuoi sang ma HTML
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ConvertTexttoHTML(string temp)
    {
        temp = temp.Replace("<", "&lt;");
        temp = temp.Replace(">", "&gt;");
        return temp;
    }

    /// <summary>
    /// Chuyen ma HTML thanh chuoi
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ConvertHTMLtoText(string temp)
    {
        temp = temp.Replace("&lt;", "<");
        temp = temp.Replace("&gt;", ">");
        temp = temp.Replace(Convert.ToString((char)13), "<br/>");
        return temp;
    }

    /// <summary>
    /// Xu ly hien thi du lieu o Gridview
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    protected string Format(object obj)
    {
        if (obj == null || obj.ToString() == "")
            return "";
        string text = obj.ToString();
        if (text == "0")
            return "定年";
        if (text == "1")
            return "契約満了";
        if (text == "2")
            return "自己都合";
        if (text == "3")
            return "会社都合";
        if (text == "4")
            return "失踪";
        if (text == "5")
            return "その他";
        return "";
    }

    protected void grv_human_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "javascript:__doPostBack('ctl00$ContentPlaceHolder1$grv_human','Load$" + e.Row.RowIndex + "')");
        }
    }

    /// <summary>
    /// Hien thi du lieu rong cho Gridview
    /// </summary>
    /// <param name="grv"></param>
    /// <param name="strTableHeader"></param>
    /// <param name="strEmpty"></param>
    public void ShowGridViewNotClassEmpty(GridView grv, string strTableHeader, string strEmpty)
    {
        DataTable dt = new DataTable();
        string[] arrColumnNames = strTableHeader.Split(',');
        foreach (string str in arrColumnNames)
        {
            dt.Columns.Add(str);
        }
        grv.ShowFooter = false;
        DataRow r = dt.NewRow();
        dt.Rows.InsertAt(r, 0);
        grv.DataSource = dt;
        grv.DataBind();
        grv.Rows[0].Cells.Clear();
        TableCell cell = new TableCell();
        cell.ColumnSpan = grv.Columns.Count + 1;
        cell.Text = strEmpty;
        grv.Rows[0].Cells.Add(cell);

    }

    public string formatStyle1(object chuoi)
    {
        if (chuoi == null || chuoi.ToString() == "")
            return "";
        string value = chuoi.ToString();
        if (value == "1")
            return "新規";
        if (value == "0")
            return "即戦力（途中）";
        return "";
    }

    protected void grv_human_PreRender(object sender, EventArgs e)
    {
        if (ViewState["IdCurrent_39"] != null && ViewState["IdCurrent_39"] != "")
        {
            if (string.IsNullOrEmpty(ViewState["IdCurrent_39"].ToString()))
                return;

            for (int i = 0; i < grv_human.Rows.Count; i++)
            {
                string Id = grv_human.DataKeys[i].Value.ToString();
                string str = (string)ViewState["IdCurrent_39"];
                if (Id == str)
                {
                    grv_human.Rows[i].CssClass = "update";
                    ViewState["IdCurrent_39"] = "";
                }
            }

        }

        if (ViewState["IdCurrent_39_Output"] != null && ViewState["IdCurrent_39_Output"] != "")
        {
            if (string.IsNullOrEmpty(ViewState["IdCurrent_39_Output"].ToString()))
                return;
            for (int i = 0; i < grv_human.Rows.Count; i++)
            {
                string Id = grv_human.DataKeys[i].Value.ToString();
                string str = (string)ViewState["IdCurrent_39_Output"];
                if (Id == str)
                {
                    grv_human.Rows[i].CssClass = "insert";
                    ViewState["IdCurrent_39_Output"] = "";
                }
            }

        }


    }

    /// <summary>
    /// Xu ly viec them moi va cap nhat du lieu
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn登録_Click(object sender, EventArgs e)
    {
        入退社情報 obj = new 入退社情報();
        入退社情報Manager _manager = new 入退社情報Manager();
        obj.廃止区分 = 0;//Set default
        if (ddl_採用区分.SelectedValue.ToString() != "-1")
            obj.採用区分_1 = Int32.Parse(ddl_採用区分.SelectedValue.ToString());
        if (txt_入社年月日.Text != "")
        {
            DateTime d1 = DateTime.Parse(txt_入社年月日.Text);
            obj.入社年月日_1 = d1;
        }
        if (txt_退社年月日.Text != "")
        {
            DateTime d2 = DateTime.Parse(txt_退社年月日.Text);
            obj.退社年月日_1 = d2;
        }
        obj.入社特記事項 = ConvertHTMLtoText(txt_入社特記事項.Text);
        obj.退社特記事項 = ConvertHTMLtoText(txt_退社特記事項.Text);
        if (ddl_退職理由.SelectedValue.ToString() != "-1")
            obj.退職理由_1 = Int32.Parse(ddl_退職理由.SelectedValue.ToString());
        else
            obj.退職理由_1 = null;

        if (Request.QueryString["id"] != null && Request.QueryString["id2"] == null && Request.QueryString["id3"] == null)
        {
             string _社員ID = Request.QueryString["id"].ToString();
            obj.社員ID = Int32.Parse(_社員ID);
        }
        else if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null && Request.QueryString["id3"] == null)
        {
            string _社員ID = Request.QueryString["id"].ToString();
            obj.社員ID = Int32.Parse(_社員ID);
            string _Id = Request.QueryString["id2"].ToString();
            obj.ＩＤ = Int32.Parse(_Id);
        }
        else if (Request.QueryString["id"] == null && Request.QueryString["id2"] == null && Request.QueryString["id3"] == null)
        {
            string _社員ID = Session["社員ID"].ToString();
            obj.社員ID = Int32.Parse(_社員ID);
        }
        else if (Request.QueryString["id"] != null && Request.QueryString["id2"] != null && Request.QueryString["id3"] != null)
        {
            string _社員ID = Request.QueryString["id"].ToString();
            obj.社員ID = Int32.Parse(_社員ID);
            string _Id = Request.QueryString["id2"].ToString();
            obj.ＩＤ = Int32.Parse(_Id);
        }

        string str採用区分 = ddl_採用区分.SelectedValue.ToString();
        string str入社年月日 = txt_入社年月日.Text;
        string str退社年月日 = txt_退社年月日.Text;
        string str退職理由 = ddl_退職理由.SelectedValue.ToString();

        // Kiem tra dang o mode nao de thuc hien
        // viec chen du lieu hay cap nhat du lieu
        // cho hop ly.
        string _myPageMode = Session["ModeEmpEnterInputOrg39"] != null ? Session["ModeEmpEnterInputOrg39"].ToString() : "-1";

        if (_myPageMode == "1")
        {
            if (Session["CountingSubmitOrg39"].ToString() == ViewState["CountingSubmitOrg39"].ToString())
            {
                string _myIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
                if (_myIdCurrent == "")
                {
                    # region Day la truong hop Insert moi 1 dong du lieu.
                    //----------------Kiem tra trung truoc khi Insert-------------------------
                    //.................3 truong hop...........................................

                    //...Truong hop 1:
                    if ((str採用区分 != "-1" && str入社年月日 != "") && (str退社年月日 == "" && str退職理由 == "-1"))
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }

                    }
                    # endregion
                }

                if (_myIdCurrent != "")
                {
                    # region Day la truong hop cap nhat dong du lieu ung voi ID duoc chon o GridView.

                    //...Truong hop 1:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";

                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {
                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }

                    #endregion
                }
            }
            else
            {
                string _社員ID = Request.QueryString["id"].ToString();
                ShowDataPageLoadFirtInsertMode(_社員ID);
            }
        }



        if (_myPageMode == "2")
        {
            #region Cap nhat 1 dong du lieu ung voi ID va 社員ID

            //string _myIdCurrent = obj.ＩＤ.ToString();
            string _myIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
            if (_myIdCurrent == "")
            {
                _myIdCurrent = obj.ＩＤ.ToString();
                // Update dong dau tien cua GirdView
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            btn登録.Text = "登録";
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            ViewState["FirstRowUpdateOrg39"] = false;
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 2:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                            ViewState["FirstRowUpdateOrg39"] = false;
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 3:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                            ViewState["FirstRowUpdateOrg39"] = false;
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
            }

            if (_myIdCurrent != "")
            {
                obj.ＩＤ = Int32.Parse(_myIdCurrent);
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            btn登録.Text = "登録";
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 2:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 3:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
            }
            
            # endregion
        }


        if (_myPageMode == "3")
        {
            if (Session["CountingSubmitOrg39"].ToString() == ViewState["CountingSubmitOrg39"].ToString())
            {
                string _myIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
                if (_myIdCurrent == "")
                {
                    # region Day la truong hop Insert moi 1 dong du lieu.
                    //----------------Kiem tra trung truoc khi Insert-------------------------
                    //.................3 truong hop...........................................

                    //...Truong hop 1:
                    if ((str採用区分 != "-1" && str入社年月日 != "") && (str退社年月日 == "" && str退職理由 == "-1"))
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }

                    }
                    # endregion
                }

                if (_myIdCurrent != "")
                {
                    # region Day la truong hop cap nhat dong du lieu ung voi ID duoc chon o GridView.

                    //...Truong hop 1:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";

                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {
                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    // LoadDataWith_社員ID(obj.社員ID.ToString());
                                    ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }

                    #endregion
                }
            }
            else
            {
                string _社員ID = Session["社員ID"].ToString();
                ShowDataPageLoadFirtInsertMode(_社員ID);
            }
        }


        if (_myPageMode == "4")
        {
            #region Cap nhat 1 dong du lieu ung voi ID va 社員ID

            //string _myIdCurrent = obj.ＩＤ.ToString();
            string _myIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
            if (_myIdCurrent == "")
            {
                string boolFirtRowUpdate = ViewState["FirstRowUpdateOrg39"] != null ? ViewState["FirstRowUpdateOrg39"].ToString() : "Fasle";
                if (boolFirtRowUpdate == "True" || boolFirtRowUpdate == "true")
                {
                    _myIdCurrent = obj.ＩＤ.ToString();
                    // Update dong dau tien cua GirdView
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                    btn登録.Text = "登録";
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    ViewState["FirstRowUpdateOrg39"] = false;
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {

                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                    ViewState["FirstRowUpdateOrg39"] = false;
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        int intIdCurrent = Int32.Parse(_myIdCurrent);
                        bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                        if (check_duplicate)
                        {
                            //Chua thay doi thong tin update
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                                ViewState["FirstRowUpdateOrg39"] = false;
                            }
                        }
                        else
                        {
                            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                            if (!flag)
                            {
                                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                                if (kq != 0 && kq != -1)
                                {
                                    ViewState["IdCurrent_39"] = _myIdCurrent;
                                    ViewState["IdCurrent"] = "";
                                    ClearTextPage();
                                    LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                    btn登録.Text = "登録";
                                    ViewState["FirstRowUpdateOrg39"] = false;
                                }
                            }
                            else
                            {
                                string MessageCode = GetError("ER00009");
                                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                            }
                        }
                    }
                }
                else if (boolFirtRowUpdate == "false" || boolFirtRowUpdate == "False")
                {
                    # region Day la truong hop Insert moi 1 dong du lieu.
                    //----------------Kiem tra trung truoc khi Insert-------------------------
                    //.................3 truong hop...........................................

                    //...Truong hop 1:
                    if ((str採用区分 != "-1" && str入社年月日 != "") && (str退社年月日 == "" && str退職理由 == "-1"))
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                //ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 2:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                //ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }

                    }
                    //...Truong hop 3:
                    if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int IdOutput;
                            int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
                            if (kq != 0 && IdOutput != 0)
                            {
                                ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
                                ClearTextPage();
                                // LoadDataWith_社員ID(obj.社員ID.ToString());
                                //ShowDataPageLoadAfterInsertMode(obj.社員ID.ToString());
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }

                    }
                    # endregion
                }
            }

            if (_myIdCurrent != "")
            {
                obj.ＩＤ = Int32.Parse(_myIdCurrent);
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            btn登録.Text = "登録";
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                btn登録.Text = "登録";
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 2:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {

                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
                //...Truong hop 3:
                if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
                {
                    int intIdCurrent = Int32.Parse(_myIdCurrent);
                    bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

                    if (check_duplicate)
                    {
                        //Chua thay doi thong tin update
                        int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

                        if (kq != 0 && kq != -1)
                        {
                            ViewState["IdCurrent_39"] = _myIdCurrent;
                            ViewState["IdCurrent"] = "";
                            ClearTextPage();
                            LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                            Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                            btn登録.Text = "登録";
                        }
                    }
                    else
                    {
                        bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
                        if (!flag)
                        {
                            int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

                            if (kq != 0 && kq != -1)
                            {
                                ViewState["IdCurrent_39"] = _myIdCurrent;
                                ViewState["IdCurrent"] = "";
                                ClearTextPage();
                                LoadDataWith_社員ID(obj.社員ID.ToString(), _myIdCurrent);
                                Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn登録.Text = "登録";
                            }
                        }
                        else
                        {
                            string MessageCode = GetError("ER00009");
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
                        }
                    }
                }
            }

            # endregion

        }

    }

    /// <summary>
    /// grv_human_RowCommand Event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_human_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Load"))
        {
            int pagecurrent = Int32.Parse(ViewState["indexPage"].ToString());
            int index;
            if (pagecurrent == 0)
                index = Int32.Parse(e.CommandArgument.ToString());
            else
                index = Convert.ToInt32(e.CommandArgument) + pagecurrent * 10;
            if (index == -1) return;

            // Kiem tra mode dang hoat dong khi Chon bat ki dong du lieu trong GridView
            string _myPageMode = Session["ModeEmpEnterInputOrg39"] != null ? Session["ModeEmpEnterInputOrg39"].ToString() : "-1";

            if (_myPageMode == "1" || _myPageMode=="3")
            {
                DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs1"];
                if (dt != null && dt.Rows.Count > 0)
                {
                    string temp1 = dt.Rows[index]["採用区分"].ToString();
                    string temp2 = dt.Rows[index]["入社年月日"].ToString();
                    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                    string temp5 = dt.Rows[index]["退職理由"].ToString();
                    string temp6 = dt.Rows[index]["退社年月日"].ToString();

                    if (temp1 != "")
                    {
                        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                    }
                    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                    txt_入社特記事項.Text = temp3;
                    txt_退社特記事項.Text = temp4;
                    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                    if (temp5 != "")
                    {
                        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                    }

                    ViewState["IdCurrent"] = dt.Rows[index]["ID"].ToString();
                    ViewState["indexOrg39"] = index.ToString();
                    btn登録.Text = "更新";
                }
                else
                {
                    string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
                    ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
                }
            }

            if (_myPageMode == "2" || _myPageMode == "4")
            {
                DataTable dt = (DataTable)ViewState["TempTableLoadOrg39ModeIs2"];
                if (dt != null && dt.Rows.Count > 0)
                {
                    string temp1 = dt.Rows[index]["採用区分"].ToString();
                    string temp2 = dt.Rows[index]["入社年月日"].ToString();
                    string temp3 = dt.Rows[index]["入社特記事項"].ToString();
                    string temp4 = dt.Rows[index]["退社特記事項"].ToString();
                    string temp5 = dt.Rows[index]["退職理由"].ToString();
                    string temp6 = dt.Rows[index]["退社年月日"].ToString();

                    if (temp1 != "")
                    {
                        ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
                        ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
                    }
                    txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
                    txt_入社特記事項.Text = temp3;
                    txt_退社特記事項.Text = temp4;
                    txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

                    if (temp5 != "")
                    {
                        ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
                        ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
                    }

                    ViewState["IdCurrent"] = dt.Rows[index]["ID"].ToString();
                    ViewState["indexOrg39"] = index.ToString();
                    btn登録.Text = "更新";
                    ViewState["FirstRowUpdateOrg39"] = false;
                }
                else
                {
                    string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
                    ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
                }
            }
        }
    }




    # region KhongSuDung
    /// <summary>
    /// Do du lieu vao gridView
    /// </summary>
    //protected void LoadData()
    //{

    //    入退社情報Manager mana_ = new 入退社情報Manager();
    //    //List<入退社情報> lst = mana_.SelectPartial(Session["社員ID"].ToString());
    //    //if (lst.Count > 0)
    //    //{
    //    //    grv_human.DataSource = lst;
    //    //    grv_human.DataBind();
    //    //}
    //    //else
    //    //    AppCode_Common.ShowEmtyGrid<入退社情報>(grv_human, 5, "データーがありません。", "");

    //    DataTable dt = mana_.SelectPartialTable(Session["社員ID"].ToString());
    //    if (dt.Rows.Count > 0)
    //    {
    //        grv_human.DataSource = dt;
    //        grv_human.DataBind();
    //        ViewState["TempTableLoadOrg39"] = dt;
    //    }
    //    else
    //    {
    //        string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
    //        ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
    //    }
    //}


    //protected void btn登録_Click(object sender, EventArgs e)
    //{

    //    if (ddl_採用区分.SelectedIndex == 0 && ddl_退職理由.SelectedIndex == 0 && txt_退社特記事項.Text == "" && txt_退社年月日.Text == "" && txt_入社特記事項.Text == "" && txt_入社年月日.Text == "")
    //    {
    //        LoadData();
    //    }
    //    else
    //    {
    //        if (Session["CountingSubmitOrg39"].ToString() == ViewState["CountingSubmitOrg39"].ToString())
    //        {
    //            if (Page.IsValid == true)
    //            {
    //                SaveData();
    //            }
    //        }
    //        else
    //        {
    //            ClearTextPage();
    //            LoadData();
    //        }
    //    }
    //}

    /// <summary>
    /// Luu du lieu xuong CSDL
    /// </summary>
    //protected void SaveData()
    //{
    //    //////////////////////////////////////////////////////////////////////////////////////////
    //    //----------------------------Truong hop insert moi 1 dong moi----------------------------
    //    /////////////////////////////////////////////////////////////////////////////////////////////
    //    string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
    //    if (strIdCurrent == "")
    //    {
    //        //------------------------------------------------Mode is insert----------------------------------------------
    //        入退社情報 obj = new 入退社情報();

    //        obj.廃止区分 = 0;//Set default
    //        if (ddl_採用区分.SelectedValue.ToString() != "-1")
    //            obj.採用区分_1 = Int32.Parse(ddl_採用区分.SelectedValue.ToString());
    //        if (txt_入社年月日.Text != "")
    //        {
    //            DateTime d1 = DateTime.Parse(txt_入社年月日.Text);
    //            obj.入社年月日_1 = d1;
    //        }
    //        if (txt_退社年月日.Text != "")
    //        {
    //            DateTime d2 = DateTime.Parse(txt_退社年月日.Text);
    //            obj.退社年月日_1 = d2;
    //        }
    //        obj.入社特記事項 = ConvertHTMLtoText(txt_入社特記事項.Text);
    //        obj.退社特記事項 = ConvertHTMLtoText(txt_退社特記事項.Text);
    //        if (ddl_退職理由.SelectedValue.ToString() != "-1")
    //            obj.退職理由_1 = Int32.Parse(ddl_退職理由.SelectedValue.ToString());
    //        else
    //            obj.退職理由_1 = null;

    //        obj.社員ID = Int32.Parse(Session["社員ID"].ToString());

    //        //----------------Kiem tra trung truoc khi Insert-------------------------
    //        //.................3 truong hop...........................................
    //        入退社情報Manager _manager = new 入退社情報Manager();
    //        string str採用区分 = ddl_採用区分.SelectedValue.ToString();
    //        string str入社年月日 = txt_入社年月日.Text;
    //        string str退社年月日 = txt_退社年月日.Text;
    //        string str退職理由 = ddl_退職理由.SelectedValue.ToString();

    //        //...Truong hop 1:
    //        if ((str採用区分 != "-1" && str入社年月日 != "") && (str退社年月日 == "" && str退職理由 == "-1"))
    //        {
    //            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
    //            if (!flag)
    //            {
    //                int IdOutput;
    //                int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
    //                if (kq != 0 && IdOutput != 0)
    //                {
    //                    //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "MB", "clearText();", true);
    //                    ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
    //                    ClearTextPage();
    //                    LoadData();
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                }
    //            }
    //            else
    //            {
    //                string MessageCode = GetError("ER00009");
    //                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
    //            }

    //        }
    //        //...Truong hop 2:
    //        if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
    //        {
    //            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
    //            if (!flag)
    //            {
    //                int IdOutput;
    //                int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
    //                if (kq != 0 && IdOutput != 0)
    //                {
    //                    ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
    //                    ClearTextPage();
    //                    LoadData();
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                }
    //            }
    //            else
    //            {
    //                string MessageCode = GetError("ER00009");
    //                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
    //            }

    //        }
    //        //...Truong hop 3:
    //        if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
    //        {
    //            bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
    //            if (!flag)
    //            {
    //                int IdOutput;
    //                int kq = new 入退社情報Manager().sp_Insert入退社情報_39(obj, out IdOutput);//save object to Database
    //                if (kq != 0 && IdOutput != 0)
    //                {
    //                    ViewState["IdCurrent_39_Output"] = IdOutput.ToString();
    //                    ClearTextPage();
    //                    LoadData();
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                }
    //            }
    //            else
    //            {
    //                string MessageCode = GetError("ER00009");
    //                Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
    //            }

    //        }
    //    }
    //    else if (strIdCurrent != "")
    //    {
    //        ////////////////////////////////////////////////////////////////////////////////////////////////////
    //        //-----------------------------------------Mode is update of insert-------------------------------
    //        ////////////////////////////////////////////////////////////////////////////////////////////////////
    //        入退社情報 obj = new 入退社情報();

    //        if (ddl_採用区分.SelectedValue.ToString() != "-1")
    //            obj.
    //                採用区分_1 = Int32.Parse(ddl_採用区分.SelectedValue.ToString());
    //        if (txt_入社年月日.Text != "")
    //        {
    //            DateTime d1 = DateTime.Parse(txt_入社年月日.Text);
    //            obj.入社年月日_1 = d1;
    //        }
    //        if (txt_退社年月日.Text != "")
    //        {
    //            DateTime d2 = DateTime.Parse(txt_退社年月日.Text);
    //            obj.退社年月日_1 = d2;
    //        }
    //        obj.入社特記事項 = ConvertHTMLtoText(txt_入社特記事項.Text);
    //        obj.退社特記事項 = ConvertHTMLtoText(txt_退社特記事項.Text);
    //        if (ddl_退職理由.SelectedValue.ToString() != "-1")
    //            obj.退職理由_1 = Int32.Parse(ddl_退職理由.SelectedValue.ToString());

    //        入退社情報Manager _manager = new 入退社情報Manager();
    //        string str採用区分 = ddl_採用区分.SelectedValue.ToString();
    //        string str入社年月日 = txt_入社年月日.Text;
    //        string str退社年月日 = txt_退社年月日.Text;
    //        string str退職理由 = ddl_退職理由.SelectedValue.ToString();
    //        obj.社員ID = Int32.Parse(Session["社員ID"].ToString());

    //        //...Truong hop 1:
    //        if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 == "-1")
    //        {
    //            int intIdCurrent = Int32.Parse(strIdCurrent);
    //            bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

    //            if (check_duplicate)
    //            {
    //                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

    //                if (kq != 0 && kq != -1)
    //                {
    //                    ViewState["IdCurrent_39"] = strIdCurrent;
    //                    ViewState["IdCurrent"] = "";
    //                    ClearTextPage();
    //                    LoadData();
    //                    btn登録.Text = "登録";
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                }
    //            }
    //            else
    //            {
    //                bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 1);
    //                if (!flag)
    //                {

    //                    int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

    //                    if (kq != 0 && kq != -1)
    //                    {
    //                        ViewState["IdCurrent_39"] = strIdCurrent;
    //                        ViewState["IdCurrent"] = "";
    //                        ClearTextPage();
    //                        LoadData();
    //                        btn登録.Text = "登録";
    //                        Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                    }
    //                }
    //                else
    //                {
    //                    string MessageCode = GetError("ER00009");
    //                    Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 1", "alert('" + MessageCode + "');", true);
    //                }
    //            }
    //        }
    //        //...Truong hop 2:
    //        if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 != "" && str退職理由 != "-1")
    //        {
    //            int intIdCurrent = Int32.Parse(strIdCurrent);
    //            bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

    //            if (check_duplicate)
    //            {
    //                //Chua thay doi thong tin update
    //                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

    //                if (kq != 0 && kq != -1)
    //                {
    //                    ViewState["IdCurrent_39"] = strIdCurrent;
    //                    ViewState["IdCurrent"] = "";
    //                    ClearTextPage();
    //                    LoadData();
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                    btn登録.Text = "登録";
    //                }
    //            }
    //            else
    //            {
    //                bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
    //                if (!flag)
    //                {

    //                    int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

    //                    if (kq != 0 && kq != -1)
    //                    {
    //                        ViewState["IdCurrent_39"] = strIdCurrent;
    //                        ViewState["IdCurrent"] = "";
    //                        ClearTextPage();
    //                        LoadData();
    //                        Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                        btn登録.Text = "登録";
    //                    }
    //                }
    //                else
    //                {
    //                    string MessageCode = GetError("ER00009");
    //                    Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 2", "alert('" + MessageCode + "');", true);
    //                }
    //            }
    //        }
    //        //...Truong hop 3:
    //        if (str採用区分 != "-1" && str入社年月日 != "" && str退社年月日 == "" && str退職理由 != "-1")
    //        {
    //            int intIdCurrent = Int32.Parse(strIdCurrent);
    //            bool check_duplicate = _manager.checkExists採用区分_入社年月日_退社年月日_Update(obj, intIdCurrent);

    //            if (check_duplicate)
    //            {
    //                //Chua thay doi thong tin update
    //                int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);

    //                if (kq != 0 && kq != -1)
    //                {
    //                    ViewState["IdCurrent_39"] = strIdCurrent;
    //                    ViewState["IdCurrent"] = "";
    //                    ClearTextPage();
    //                    LoadData();
    //                    Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                    btn登録.Text = "登録";
    //                }
    //            }
    //            else
    //            {
    //                bool flag = _manager.checkSame採用区分_入社年月日_退社年月日_Insert(obj, 2);
    //                if (!flag)
    //                {
    //                    int kq = new 入退社情報Manager().Update入退社情報_Partial(obj, intIdCurrent);//save object to Database

    //                    if (kq != 0 && kq != -1)
    //                    {
    //                        ViewState["IdCurrent_39"] = strIdCurrent;
    //                        ViewState["IdCurrent"] = "";
    //                        ClearTextPage();
    //                        LoadData();
    //                        Session["CountingSubmitOrg39"] = Server.UrlEncode(System.DateTime.Now.ToString());
    //                        btn登録.Text = "登録";
    //                    }
    //                }
    //                else
    //                {
    //                    string MessageCode = GetError("ER00009");
    //                    Page.ClientScript.RegisterStartupScript(typeof(Page), "Same 3", "alert('" + MessageCode + "');", true);
    //                }
    //            }
    //        }
    //    }
    //}

    /// <summary>
    /// grv_human_RowCommand
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void grv_human_RowCommand(object sender, GridViewCommandEventArgs e)
    //{
    //    if (e.CommandName.Equals("Load"))
    //    {
    //        int pagecurrent = Int32.Parse(ViewState["indexPage"].ToString());
    //        int index;
    //        if (pagecurrent == 0)
    //            index = Int32.Parse(e.CommandArgument.ToString());
    //        else
    //            index = Convert.ToInt32(e.CommandArgument) + pagecurrent * 10;
    //        if (index == -1) return;

    //        DataTable dt = null;
    //        //dt = new 入退社情報Manager().SelectPartialTable(Session["社員ID"].ToString());
    //        dt = (DataTable)ViewState["TempTableLoadOrg39"];
    //        if (dt != null && dt.Rows.Count > 0)
    //        {
    //            string temp1 = dt.Rows[index]["採用区分"].ToString();
    //            string temp2 = dt.Rows[index]["入社年月日"].ToString();
    //            string temp3 = dt.Rows[index]["入社特記事項"].ToString();
    //            string temp4 = dt.Rows[index]["退社特記事項"].ToString();
    //            string temp5 = dt.Rows[index]["退職理由"].ToString();
    //            string temp6 = dt.Rows[index]["退社年月日"].ToString();

    //            if (temp1 != "")
    //            {
    //                ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
    //                ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
    //            }
    //            txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
    //            txt_入社特記事項.Text = temp3;
    //            txt_退社特記事項.Text = temp4;
    //            txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

    //            if (temp5 != "")
    //            {
    //                ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
    //                ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
    //            }

    //            ViewState["IdCurrent"] = dt.Rows[index]["ID"].ToString();
    //            ViewState["indexOrg39"] = index.ToString();
    //            ViewState["入退社情報TableOrg39"] = dt;
    //            btn登録.Text = "更新";
    //        }
    //        else
    //        {
    //            string strHeader = "採用区分,入社年月日,入社特記事項,退社年月日,退社特記事項,退職理由,ID";
    //            ShowGridViewNotClassEmpty(grv_human, strHeader, "データーがありません。");
    //        }
    //    }
    //}


    //protected void btnリセット_Click(object sender, EventArgs e)
    //{
    //    //ViewState["IdCurrent"] = "";
    //    //ViewState["IdCurrent_39"] = "";
    //    ddl_採用区分.Focus();
    //    //btn登録.Text = "登録";

    //    //ClearTextPage();
    //    //LoadData();
    //    string strIdCurrent = ViewState["IdCurrent"] != null ? ViewState["IdCurrent"].ToString() : "";
    //    if (strIdCurrent != "")
    //    {
    //        DataTable dt = (DataTable)ViewState["入退社情報TableOrg39"];
    //        int index = Int32.Parse(ViewState["indexOrg39"].ToString());

    //        string temp1 = dt.Rows[index]["採用区分"].ToString();
    //        string temp2 = dt.Rows[index]["入社年月日"].ToString();
    //        string temp3 = dt.Rows[index]["入社特記事項"].ToString();
    //        string temp4 = dt.Rows[index]["退社特記事項"].ToString();
    //        string temp5 = dt.Rows[index]["退職理由"].ToString();
    //        string temp6 = dt.Rows[index]["退社年月日"].ToString();

    //        if (temp1 != "")
    //        {
    //            ListItem lst1 = ddl_採用区分.Items.FindByValue(temp1);
    //            ddl_採用区分.SelectedIndex = ddl_採用区分.Items.IndexOf(lst1);
    //        }
    //        txt_入社年月日.Text = (temp2 != "" ? temp2.Substring(0, 10) : "");
    //        txt_入社特記事項.Text = temp3;
    //        txt_退社特記事項.Text = temp4;
    //        txt_退社年月日.Text = (temp6 != "" ? temp6.Substring(0, 10) : "");

    //        if (temp5 != "")
    //        {
    //            ListItem lst = ddl_退職理由.Items.FindByValue(temp5);
    //            ddl_退職理由.SelectedIndex = ddl_退職理由.Items.IndexOf(lst);
    //        }
    //        else
    //        {
    //            ddl_退職理由.SelectedIndex = 0;
    //        }
    //    }
    //    else
    //    {
    //        ClearTextPage();
    //        LoadData();
    //    }
    //}

    # endregion


}
